home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
hub.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
9KB
|
233 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
import wx
from gui.authorizationdialog import AuthorizationDialog
from logging import getLogger
log = getLogger('hub')
info = log.info
from util.singletonmixin import Singleton
from util import Delegate, traceguard, get
from common import profile, fire
from cStringIO import StringIO
from PIL import Image
import sys
from common.protocolmeta import protocols
PROMOTE_STRING = '<br><br>I use <a href="http://www.digsby.com">digsby</a>!'
global_locale = wx.Locale(wx.LANGUAGE_DEFAULT)
_locale_obj = [
global_locale.GetCanonicalName(),
sys.getfilesystemencoding()]
class Hub(Singleton):
def __init__(self):
Singleton.__init__(self)
self.getting_profile_for = None
def signoff(self):
pass
def filter_message(self, mobj, *a, **k):
conv = mobj.conversation
conn = conv.protocol
if not mobj.buddy:
pass
buddy = mobj.conversation.buddy
if conn.allow_message(buddy, mobj) is False:
log.debug('Message from %r is being ignored', buddy)
log.debug_s('The message was %r', mobj)
return Delegate.VETO
def launchurl(self, url):
wx.LaunchDefaultBrowser(url)
def windowparent(self):
wins = wx.GetTopLevelWindows()
return None if wins else None
def get_file(self, msg = 'Choose a file'):
filediag = wx.FileDialog(self.windowparent(), msg)
if filediag.ShowModal() == wx.ID_OK:
return filediag.GetPath()
def get_dir(self, msg = 'Choose a directory'):
dirdiag = wx.DirDialog(self.windowparent(), msg)
return None if dirdiag.ShowModal() == wx.ID_OK else None
def on_conversation(self, convo, quiet = False):
log.critical('on_conversation is deprecated and does nothing')
def send_message(self, buddy, message):
buddy.protocol.send_message(buddy = buddy.name, msg = message)
def user_message(self, message, title = ''):
wx.CallAfter(wx.MessageBox, message, title)
def on_error(self, e):
import traceback as traceback
log.error(traceback.format_exc())
title = get(e, 'header', 'Error:')
msg = get(e, 'major', '%s: %s' % (type(e).__name__, str(e)))
details = get(e, 'minor', '')
close = (_('Close'), (lambda : pass))
fire('error', title = title, msg = msg, details = details, sticky = True, popupid = Exception, buttons = (close,), update = 'replace')
def call_later(self, c, *a, **k):
c(*a, **k)
def on_file_request(self, protocol, xferinfo):
type = xferinfo.type
if xferinfo not in profile.xfers:
xferinfo.state = xferinfo.states.WAITING_FOR_YOU
notifies = fire('filetransfer.request', buddy = xferinfo.buddy, target = xferinfo)
xferinfo.notifications = notifies
profile.xfers.insert(0, xferinfo)
def on_direct_connect(self, dc):
caption = _('%s DirectIM') % dc.protocol.name.capitalize()
msg = _('%s wants to directly connect with you. (Your IP address will be revealed.)' % dc.buddy.name)
None if self.popup(msg, caption) else dc.decline()
def on_invite(self, protocol, buddy, room_name, message = '', on_yes = None, on_no = None):
log.info('chat rooms are not implemented')
return None if on_no is not None else None
def authorize_buddy(self, protocol, buddy, message = '', username_added = None, callback = None):
message = message.strip()
if message:
message = '\n\n"%s"' % message
if hasattr(buddy, 'name'):
buddy = buddy.name
if callback is None:
callback = protocol.authorize_buddy
if username_added is None:
username_added = protocol.username
if buddy != protocol.self_buddy.name:
diag_message = _('Allow %s to add you (%s) as a buddy on %s?%s') % (buddy, username_added, protocols[protocol.service].name, message)
ad = AuthorizationDialog(protocol, buddy, diag_message, username_added, callback)
ad.Show(True)
else:
callback(buddy, True, username_added)
def on_mail(self, protocol, inbox_count, others_count = None):
log.info('%s has %s new mail messages', protocol.username, inbox_count)
if others_count:
log.info('%s has %s new OTHER mail messages', protocol.username, others_count)
def send_typing_status(self, buddy, status):
buddy.protocol.send_typing_status(buddy.name, status)
def set_buddy_icon(self, wximage):
img = wximage.PIL
(w, h) = img.size
max = profile.MAX_ICON_SIZE
if w > max or h > max:
img = img.Resized(max)
imgFile = StringIO()
img.save(imgFile, 'PNG', optimize = True)
self.set_buddy_icon_file(imgFile.getvalue())
def set_buddy_icon_file(self, bytes):
if hasattr(bytes, 'read'):
bytes = bytes.read()
if not isinstance(bytes, str):
raise TypeError
maxsz = profile.MAX_ICON_SIZE
maxbytes = MAX_BLOB_SIZE
import digsby.abstract_blob
nextsize = maxsz
tries = 0
while len(bytes) > maxbytes and tries < 10:
log.warning('image (%dx%d) is larger than %d bytes, have to resize', nextsize, nextsize, maxbytes)
img = Image.open(StringIO(bytes)).Resized(nextsize)
newimg = StringIO()
img.save(newimg, 'PNG', optimize = True)
bytes = newimg.getvalue()
nextsize = max(20, nextsize - 10)
tries += 1
log.info('setting %d bytes of icon data (max is %d): %s', len(bytes), maxbytes, bytes[:5])
profile.save_blob('icon', bytes)
for acct in profile.account_manager.connected_accounts:
traceguard.__enter__()
try:
acct.connection.set_and_size_icon(bytes)
finally:
pass
def get_locale(self):
return _locale_obj
def get_lang_country(self):
lang_country = self.get_locale()[0]
(lang, country) = lang_country.split('_')
return (lang, country.lower().split('@')[0])
def get_country(self):
return self.get_lang_country()[1]
country = property(get_country)
def get_encoding(self):
return self.get_locale()[1]
def ProcessEvent(self, e):
print 'ProcessEvent', e
def get_language(self):
return self.get_lang_country()[0]
language = property(get_language)
def getThreadsafeInstance(cls):
ThreadsafeGUIProxy = ThreadsafeGUIProxy
import events
return ThreadsafeGUIProxy(cls.getInstance())
getThreadsafeInstance = classmethod(getThreadsafeInstance)
get_instance = Hub.getInstance
def diskspace_check(size):
return True